package Gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.rmi.RemoteException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;

import domein.server.IBuilder;

public class MainFrame extends JFrame {
	
	private JTextPane textPane;
	
	public MainFrame(int id, IBuilder builder) throws RemoteException{
		super(id+"");
		Container cp = getContentPane();
		cp.setLayout(new BorderLayout());
		
		// 3 bars aanmaken		
		textPane = new JTextPane();
		
		textPane.setStyledDocument((builder.read(id)));
		textPane.setPreferredSize(new Dimension(190,190));
		
		JPanel head = new MyOptionBar(textPane, 
				new TextFieldHandler(builder, id, textPane), new ForceUpdateHandler(textPane, builder, id));
		head.setSize(new Dimension(200,10));
		head.setBackground(Color.RED);
		
		//TextLineNumber lines = new TextLineNumber(textPane);
		JPanel lines = new JPanel();
		lines.setSize(new Dimension(10,200));
		lines.setBackground(Color.GREEN);
		
		cp.add(head, BorderLayout.PAGE_START);
		//cp.add(lines, BorderLayout.LINE_START);
		cp.add(textPane, BorderLayout.CENTER);
		
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		pack();
		setVisible(true);
		
	}

	public JTextPane getTextPane() {
		return textPane;
	}

	public void setTextPane(JTextPane textPane) {
		this.textPane = textPane;
	}

	public void update(IBuilder builder, int iD) {
		SwingUtilities.invokeLater(new MyInvokeLater(textPane,builder,iD));		
	}

}
